<?php
	error_reporting(E_ALL); // выводим все ошибки
	session_start();
  define('PAGE_AMOUNT', 30);
  		
	//include core files
  chdir('/home/www/z182452/htdocs/');
	include("./cfg/connect.inc.php");
	include("./includes/database/mysql.php");
	include("./cfg/functions.php");
  chdir('/home/www/z182452/htdocs/grabber');

	//connect to the database
	db_connect(DB_HOST,DB_USER,DB_PASS) or die (db_error());
	db_select_db(DB_NAME) or die (db_error());
  db_query("SET NAMES 'utf8';") or die(db_error());

  //Считываем GET-переменные
  // page             - номер страницы
  // maxQ             - максимальное кол-во запросов в месяц
  // dir              - кол-во объявлений
    if(isset($_GET["page"])){
      $page  = $_GET["page"];
    }else{
      $page = 1; 
    }
    
    if(isset($_GET["maxQ"])){
      $maxQ  = $_GET["maxQ"];
    }else{
      $maxQ = 20000; 
    }
    
    if(isset($_GET["dir"])){
      $dir  = $_GET["dir"];
    }else{
      $dir = 0; 
    }
    
  echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
            <script src="delScript.js" type="text/javascript"></script>
          </head><body>';
    
      // цикл по словам
      $q_str = "SELECT words,cnt_wst,ID FROM grab_queries q where wst_flag = 1 AND cnt_wst > 5000 AND cnt_wst < $maxQ AND cnt_dir=$dir AND
                                      NOT EXISTS(select 'x' from grab_useless where words = q.words) ";
      $offset=($page-1)* PAGE_AMOUNT;
      $q_str .= " LIMIT $offset,".PAGE_AMOUNT; 
      $q = db_query($q_str) or die (db_error());
      echo '<table>';
      while($row=db_fetch_row($q)){
          echo '<tr><td><a href=# id="'.$row[0].'">del</a></td><td>'.$row[0].'</td><td>'.$row[1].'</td></tr>';
      }
      echo '</table>';
      echo '</body></html>';

?>
